import { ROUTES } from './routes'

/**
 * 路由工具函数
 */

/**
 * 判断是否为登录页面
 */
export const isLoginRoute = (pathname: string): boolean => {
  return pathname === ROUTES.LOGIN
}

/**
 * 判断是否为受保护的路由
 */
export const isProtectedRoute = (pathname: string): boolean => {
  return !isLoginRoute(pathname)
}

/**
 * 获取路由标题
 */
export const getRouteTitle = (pathname: string): string => {
  switch (pathname) {
    case ROUTES.LOGIN:
      return '登录'
    case ROUTES.HOME:
      return '主页管理'
    case ROUTES.HOMEPAGE:
      return '主页管理'
    case ROUTES.VIDEOS:
      return '视频列表'
    case ROUTES.SINGLE_VIDEO:
      return '单作品提取'
    case ROUTES.COLLECTION:
      return '合集提取'
    case ROUTES.KEYWORD:
      return '关键词提取'
    case ROUTES.TOPIC:
      return '话题提取'
    case ROUTES.MY_HOMEPAGE:
      return '我的主页提取'
    case ROUTES.MY_PROFILE:
      return '我的主页提取'
    default:
      return '抖乎'
  }
}

/**
 * 构建带参数的路由路径
 */
export const buildPath = (path: string, params?: Record<string, string | number>): string => {
  if (!params) return path
  
  let result = path
  Object.entries(params).forEach(([key, value]) => {
    result = result.replace(`:${key}`, String(value))
  })
  
  return result
}

/**
 * 添加查询参数到路由
 */
export const addQueryParams = (
  path: string,
  params: Record<string, string | number | boolean>
): string => {
  const searchParams = new URLSearchParams()
  
  Object.entries(params).forEach(([key, value]) => {
    searchParams.append(key, String(value))
  })
  
  const queryString = searchParams.toString()
  return queryString ? `${path}?${queryString}` : path
}

